/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 jfinal app. jfapp Group.
 */

package app.models.activity;

import com.github.sog.annotation.TableBind;
import com.github.sog.plugin.sqlinxml.SqlKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;

import java.util.List;

/**
 * <p>
 * 品牌活动关联 The table ol_brandrf_activity mapping model.
 * </p>
 */
@TableBind(tableName = "ol_brandrf_activity")
public class BrandrfActivity extends Model<BrandrfActivity> {

    private static final long   serialVersionUID = 1L;
    /**
     * The public dao.
     */
    public static final BrandrfActivity dao = new BrandrfActivity();


    public List<BrandrfActivity> list(){
    	return find(SqlKit.sql("brandrfactivity.list"));
    }


    /**
     *根据活动id删除所有和该活动关联的品牌活动信息
     * @param ids 活动ids
     * @return
     */
    public boolean delByActivity(List<String> ids){
        int size = ids.size();
        Object[][] objects = new Object[size][];
        for (int i = 0; i < size; i++) {
            Object[] obj = new Object[1];
            obj[0]=ids.get(i);
            objects[i]=obj;
        }
        int[] batch = Db.batch(SqlKit.sql("brandrfactivity.delByActivity"), objects, 50);
        for (int i = 0; i < batch.length; i++) {
            if(batch[i]<=0){
                return false;
            }
        }
        return true;
    }
}